SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.[DnnProduct_GetEventLog]
 @PortalID int,
 @LogTypeKey nvarchar(35),
 @PageSize int,
 @PageIndex int
AS
begin
 -- Set the page bounds
 DECLARE @PageLowerBound INT
  , @PageUpperBound INT
  , @RowsToReturn int
  , @TotalRecords int

 exec dbo.DnnProduct_CalculatePagingInformation @PageIndex, @PageSize, @RowsToReturn output, @PageLowerBound output, @PageUpperBound output

 begin with [eLog] as (
  select row_number() over (order by E.LogCreateDate desc) as rowid, e.*
  from dbo.DnnProduct_EventLog e
  where (e.LogPortalID = @PortalID or @PortalID IS NULL)
   AND (e.LogTypeKey Like @LogTypeKey or @LogTypeKey IS NULL)
 )
  select * from [eLog]
  where rowid > @PageLowerBound and rowid < @PageUpperBound
  order by rowid
 end

 select count(*) AS TotalRecords
 from dbo.DnnProduct_EventLog e
 where (e.LogPortalID = @PortalID or @PortalID IS NULL)
  AND (e.LogTypeKey Like @LogTypeKey or @LogTypeKey IS NULL)

END

GO
